package net.interfax.impl;

import net.interfax.FileType;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringEscapeUtils;

public class SendFax implements XmlSerializable {
	public SendFax(String username, String password, String faxNumber, byte[] data, FileType fileType) {
		this.username = username;
		this.password = password;
		this.faxNumber = faxNumber;
		this.data = data;
		this.fileType = fileType;
	}
	
	@Override
	public String toXml() {
		final StringBuilder builder = new StringBuilder();
		
		builder.append("<Sendfax xmlns=\"http://www.interfax.cc\">")
			.append("<Username>").append(StringEscapeUtils.escapeXml(username)).append("</Username>")
			.append("<Password>").append(StringEscapeUtils.escapeXml(password)).append("</Password>")
			.append("<FaxNumber>").append(StringEscapeUtils.escapeXml(faxNumber)).append("</FaxNumber>")
			.append("<FileData>").append(Base64.encodeBase64String(data)).append("</FileData>")
			.append("<FileType>").append(fileType).append("</FileType>")
			.append("</Sendfax>");
		
		return builder.toString();
	}
	
	public final String username;
	public final String password;
	public final String faxNumber;
	public final byte[] data;
	public final FileType fileType;
}
